const app = require('express')();
const http = require('http').Server(app);
const io = require('socket.io')(http,{cros:true});//解决存在的跨域问题
const port = process.env.PORT || 3005;

io.on('connection', (socket) => {//建立连接
  socket.on('chat message', msg => {//接收事件为chat message  的信息
    io.emit('chat1 message', msg);//发送事件为chat1 message  的信息
  });
});

http.listen(port, () => {
  console.log(`Socket.IO server running at http://localhost:${port}/`);
});
